package com.lzm.back.mapper;

import com.lzm.back.entity.Event;
import com.lzm.back.entity.EventCategory;
import com.lzm.back.entity.EventCategoryRelation;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface EventCategoryRelationMapper {

    @Insert("INSERT INTO event_category_relation(event_id, category_id) VALUES(#{eventId}, #{categoryId})")
    void insert(EventCategoryRelation relation);

    @Select("SELECT event_id FROM event_category_relation WHERE category_id = #{categoryId}")
    List<Long> selectEventIdsByCategoryId(Long categoryId);

    @Delete("DELETE FROM event_category_relation WHERE category_id = #{categoryId}")
    void deleteByCategoryId(Long categoryId);

    @Delete("DELETE FROM event_category_relation WHERE category_id = #{id}")
    void deleteByPrimaryKey(Long id);


    List<EventCategoryRelation> selectByCategoryName(
            @Param("categoryName") String categoryName
    );

    @Select("SELECT * FROM event_category")
    List<EventCategory> selectAllCategories();

    @Select("SELECT * FROM event")
    List<Event> selectAllEvents();

    // 移除@Delete注解中的动态SQL，改为XML实现
    void batchDelete(@Param("ids")List<Long> ids);

    @Transactional
    void batchInsert(@Param("categoryId") Long categoryId,@Param("eventIds") List<Long> eventIds);
}